//
//  ChangePassWordController.m
//  YIChuSeller
//
//  Created by xsj on 2018/11/23.
//  Copyright © 2018年 xiangshengjun. All rights reserved.
//

#import "GXChangePassWordController.h"
#import "LoginAndResetManager.h"
@interface GXChangePassWordController ()
@property (weak, nonatomic) IBOutlet UITextField *passwordTF;
@property (weak, nonatomic) IBOutlet UITextField *passwordAgainTF;
@property (weak, nonatomic) IBOutlet UITextField *codeTF;
@property (weak, nonatomic) IBOutlet UILabel *PhoneNumberLabel;
@property (nonatomic,copy) NSString * phoneNumberStr;
@end

@implementation GXChangePassWordController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.title = @"修改密码";
    NSString *phoneStr = [[NSUserDefaults standardUserDefaults]objectForKey:@"phoneNumber"];
    self.phoneNumberStr = phoneStr;
    self.PhoneNumberLabel.text = [NSString stringWithFormat:@"当前手机:%@",phoneStr];
    
}
- (IBAction)pressCodeBtn:(id)sender {
    if (![self checkCodeTextFieldValue]) {
        return;
    }
}
- (IBAction)pressChangePasswordBtn:(id)sender {
    if (![self checkPhoneTextFieldValue]) {
        return;
    }
    if (![self checkCodeTextFieldValue]) {
        return;
    }
     [self viewResignFirstResponder];
    NSString * passwordStr = [NSString MD5ForUpper32Bate:self.passwordTF.text];
    [LoginAndResetManager changePasswordWithPhone:self.phoneNumberStr repassword:passwordStr success:^(id responseObject) {
        if ([responseObject[@"cod"] isEqualToString:@"001"]) {
            [SVProgressHUD showSuccessWithStatus:@"修改成功"];
        }else{
            [SVProgressHUD showErrorWithStatus:responseObject[@"describa"]];
        }
    } fail:^(id responseObject) {
        
    }];
}

- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event
{
    [self viewResignFirstResponder];
}
- (void)viewResignFirstResponder
{
    [self.passwordTF resignFirstResponder];
    [self.passwordAgainTF resignFirstResponder];
    [self.codeTF resignFirstResponder];
}
# pragma mark 输入信息判断
- (BOOL)checkPhoneTextFieldValue
{
    if ([NSString isBlankString:self.passwordTF.text] || [NSString isBlankString:self.passwordAgainTF.text]) {
        [SVProgressHUD showErrorWithStatus:@"密码不能为空"];
        return NO;
    }
    if (![self.passwordTF.text isEqualToString:self.passwordAgainTF.text]) {
        [SVProgressHUD showErrorWithStatus:@"前后密码输入不一致"];
        return NO;
    }
    return YES;
}
- (BOOL)checkCodeTextFieldValue
{
    if ([NSString isBlankString:self.codeTF.text]) {
        [SVProgressHUD showErrorWithStatus:@"验证码不能为空"];
        return NO;
    }
    if (self.codeTF.text.length > 6) {
        [SVProgressHUD showErrorWithStatus:@"证码的长度不超过6"];
        return NO;
    }
    return YES;
}
@end
